<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%--
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
--%>

<!DOCTYPE html>

<html lang="zh-cn">
<head>
    <title>查看供应商</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="author" content="陈芳杰（baayso@qq.com）"/>

    <link rel="stylesheet" href="${ pageContext.request.contextPath }/jsp/lib/quick.css"/>
    <link rel="stylesheet" href="${ pageContext.request.contextPath }/jsp/css/public.css"/>
    <script type="text/javascript" src="${ pageContext.request.contextPath }/jsp/lib/jquery.js"></script>
    <script type="text/javascript" src="${ pageContext.request.contextPath }/jsp/lib/jquery.maskedinput.js"></script>

    <script type="text/javascript">

        jQuery(function($) {
        			$("#telephone").mask("099 99999999", {placeholder:"-"});
        			$("#fax").mask("099 99999999", {placeholder:"-"});
        		});

        function enableEdit() {
            var $btnEdit = $("#btnEdit");
            var $btnSave = $("#btnSave");
            var $name = $("#name");
            var $num = $("#num");
            var $unit = $("#unit");
            var $money = $("#money");
            var $isPayment = $("#isPayment");
            var $supplierName = $("#supplierId");
            var $descriptions = $("#descriptions");

            if ("编辑" == $btnEdit.text()) {
                // 将页面上的控件置为可用
                $name.attr("disabled", false);
                $num.attr("disabled", false);
                $unit.attr("disabled", false);
                $money.attr("disabled", false);
                $isPayment.attr("disabled", false);
                $supplierName.attr("disabled", false);
                $descriptions.attr("disabled", false);
                $btnEdit.text("取消");
                $btnSave.fadeIn("slow");
            }
            else {
                // 将页面上的控件置为不可用
               	$name.attr("disabled", true);
                $num.attr("disabled", true);
                $unit.attr("disabled", true);
                $money.attr("disabled", true);
                $isPayment.attr("disabled", true);
                $supplierName.attr("disabled", true);
                $descriptions.attr("disabled", true);
                $btnEdit.text("编辑");
                $btnSave.fadeOut("slow");
            }

        }

        function del(id) {
        	if (confirm("确定删除供应商信息吗？")) {
				location.href = "${ pageContext.request.contextPath }/jsp/bill/BillServlet?method=DEL&id=" + id;
			}
        }
        
        function update() {
        	if (confirm("确定要保存修改的供应商信息吗？")) {
        		$("#updateSupplierForm").submit();
			}
        }

    </script>
</head>

<body>

<div class="list">

    <div class="add">
        <span class="font_size_13">
            <a href="javascript:void(0);" class="label label-blue">查看账单 &gt;&gt;</a>
        </span>
    </div>

    <div class="col-1-1">
        <form id="updateSupplierForm" name="updateSupplierForm" class="form form-stacked" method="post" action="${ pageContext.request.contextPath }/jsp/bill/BillServlet?method=UPDATE">
            <fieldset>

                <div class="grid">

                    <input type="hidden" name="id" value="${ bill.id }"/>

                    <div class="col-1-2">
                        <label><span style="color: red;">*</span>&nbsp商品名称：</label>
                        <input type="text" id="name" name="name" placeholder="商品名称" value="${ bill.name }" disabled/>
                    </div>

                    <div class="col-1-2">
                        <label><span style="color: red;">*</span>&nbsp商品数量：</label>
                        <input type="text" id="num" name="num" placeholder="商品数量" value="${ bill.num }" disabled/>
                    </div>

                    <div class="col-1-2">
                        <label><span style="color: red;">*</span>&nbsp交易单位：</label>
                        <input type="text" id="unit" name="unit" placeholder="交易单位" value="${ bill.unit }" disabled/>
                    </div>

                    <div class="col-1-2">
                        <label><span style="color: red;">*</span>&nbsp交易金额：</label>
                        <input type="text" id="money" name="money" placeholder="交易金额" value="${ bill.money }" disabled/>
                    </div>

                    <div class="col-1-2">
                        <label><span style="color: red;">*</span>&nbsp是否付款：</label>
                        <select name="isPayment" id="isPayment" class="width_193" value="${ bill.isPayment }" disabled>
                            <option value="Y" <c:if test="${ 'Y' eq bill.isPayment }">selected</c:if> >是</option>
                            <option value="N" <c:if test="${ 'N' eq bill.isPayment }">selected</c:if> >否</option>
                        </select>
                    </div>

                    <div class="col-1-2">
                        <label><span style="color: red;">*</span>&nbsp供应商：</label>
                        <select name="supplierId" id="supplierId" class="width_193" value="${ bill.supplierId }" disabled>
                            <option value="">请选择</option>
                            <c:forEach varStatus="status" var="supplier" items="${ requestScope.supplierList }">
                                <option value="${ supplier.id }" <c:if test="${ supplier.id eq bill.supplierId }">selected</c:if> >${ supplier.name }</option>
                            </c:forEach>
                        </select>
                    </div>

                    <div class="col-1-2">
                        <label>备注：</label>
                        <textarea id="descriptions" name="descriptions" rows="2" class="x1-large" placeholder="备注" value="${ supplier.descriptions }" disabled></textarea>
                    </div>

                    <div class="col-1-1 width_830">
                        <!-- <button type="submit" class="button-blue">提交数据</button> -->
                        <a href="javascript:void(0);" id="btnEdit" class="button button-blue" onclick="enableEdit();">编辑</a>
                        <a href="javascript:void(0);" id="btnSave" class="button button-green" onclick="update();" style="display: none;">保存</a>
                        <a href="javascript:void(0);" onclick="del('${bill.id}');" class="button button-red">删除</a>
                        <a href="${ pageContext.request.contextPath }/jsp/bill/BillServlet?method=LIST" class="button button-red">返回</a>
                    </div>
                </div>

            </fieldset>
        </form>
    </div>

</div>

</body>

</html>